package com.shop.cloud.controller.goods;

import io.swagger.annotations.ApiOperation;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.shop.cloud.common.mybatis.BaseController;
import com.shop.cloud.dao.hongfu.GoodsCategoryDao;
import com.shop.cloud.dao.hongfu.GoodsDao;
import com.shop.cloud.dao.hongfu.GoodsExamineDao;
import com.shop.cloud.domain.hongfu.DescGoods;
import com.shop.cloud.domain.hongfu.DistributionInstall;
import com.shop.cloud.domain.hongfu.Goods;
import com.shop.cloud.domain.hongfu.GoodsBrand;
import com.shop.cloud.domain.hongfu.GoodsCategory;
import com.shop.cloud.domain.hongfu.GoodsCategoryFeature;
import com.shop.cloud.domain.hongfu.GoodsCategoryFeatureValue;
import com.shop.cloud.domain.hongfu.GoodsExamine;
import com.shop.cloud.domain.hongfu.GoodsFeature;
import com.shop.cloud.domain.hongfu.GoodsFeatureImage;
import com.shop.cloud.domain.hongfu.GoodsImage;
import com.shop.cloud.domain.hongfu.GoodsInventory;
import com.shop.cloud.domain.hongfu.GoodsProduct;
import com.shop.cloud.domain.hongfu.GoodsProductSku;
import com.shop.cloud.domain.hongfu.ListToMap;
import com.shop.cloud.domain.hongfu.ProductSku;
import com.shop.cloud.domain.hongfu.Shop;
import com.shop.cloud.filter.CurrentUserId;
import com.shop.cloud.model.request.AddGoodsBrandRequest;
import com.shop.cloud.model.request.AddGoodsCategoryFeatureRequest;
import com.shop.cloud.model.request.AddGoodsCategoryFeatureValueRequest;
import com.shop.cloud.model.request.AddGoodsCategoryRequest;
import com.shop.cloud.model.request.AddGoodsCategoryRequestData;
import com.shop.cloud.model.request.AddGoodsRequest;
import com.shop.cloud.model.request.CheckGoodsRequest;
import com.shop.cloud.model.request.CloseGoodsRequest;
import com.shop.cloud.model.request.DeleteGoodsBrandRequest;
import com.shop.cloud.model.request.DeleteGoodsCategoryFeatureRequest;
import com.shop.cloud.model.request.DeleteGoodsCategoryFeatureValueRequest;
import com.shop.cloud.model.request.DeleteGoodsCategoryRequest;
import com.shop.cloud.model.request.DeleteGoodsRequest;
import com.shop.cloud.model.request.EditGoodsBrandRequest;
import com.shop.cloud.model.request.EditGoodsCategoryRequest;
import com.shop.cloud.model.request.EditGoodsCategorySecondRequest;
import com.shop.cloud.model.request.EditGoodsRequest;
import com.shop.cloud.model.request.EnableCheckGoodsRequest;
import com.shop.cloud.model.request.GetAllCategoryFeatureListRequest;
import com.shop.cloud.model.request.GetAllGoodsCategoryRequest;
import com.shop.cloud.model.request.GetGoodsBrandListRequest;
import com.shop.cloud.model.request.GetGoodsCategoryFeatureListRequest;
import com.shop.cloud.model.request.GetGoodsCategoryGradeListRequest;
import com.shop.cloud.model.request.GetGoodsInfoRequest;
import com.shop.cloud.model.request.OpenGoodsRequest;
import com.shop.cloud.model.request.ViewGoodsRejectedReasonRequest;
import com.shop.cloud.model.response.AddGoodsBrandResponse;
import com.shop.cloud.model.response.AddGoodsCategoryFeatureResponse;
import com.shop.cloud.model.response.AddGoodsCategoryFeatureValueResponse;
import com.shop.cloud.model.response.AddGoodsCategoryResponse;
import com.shop.cloud.model.response.AddGoodsResponse;
import com.shop.cloud.model.response.CheckGoodsResponse;
import com.shop.cloud.model.response.CloseGoodsResponse;
import com.shop.cloud.model.response.DeleteGoodsBrandResponse;
import com.shop.cloud.model.response.DeleteGoodsCategoryFeatureResponse;
import com.shop.cloud.model.response.DeleteGoodsCategoryFeatureValueResponse;
import com.shop.cloud.model.response.DeleteGoodsCategoryResponse;
import com.shop.cloud.model.response.DeleteGoodsResponse;
import com.shop.cloud.model.response.EditGoodsBrandResponse;
import com.shop.cloud.model.response.EditGoodsCategoryResponse;
import com.shop.cloud.model.response.EditGoodsResponse;
import com.shop.cloud.model.response.EnableCheckGoodsResponse;
import com.shop.cloud.model.response.GetAllCategoryFeatureListResponse;
import com.shop.cloud.model.response.GetAllGoodsCategoryResponse;
import com.shop.cloud.model.response.GetGoodsBrandListResponse;
import com.shop.cloud.model.response.GetGoodsCategoryFeatureListResponse;
import com.shop.cloud.model.response.GetGoodsCategoryGradeListResponse;
import com.shop.cloud.model.response.GetGoodsInfoResponse;
import com.shop.cloud.model.response.OpenGoodsResponse;
import com.shop.cloud.model.response.ViewGoodsRejectedReasonResponse;
import com.shop.cloud.service.hongfu.GoodsProductService;
import com.shop.cloud.service.hongfu.GoodsProductSkuService;
import com.shop.cloud.service.hongfu.impl.DistributionInstallService;
import com.shop.cloud.service.hongfu.impl.GoodsBrandService;
import com.shop.cloud.service.hongfu.impl.GoodsCategoryFeatureService;
import com.shop.cloud.service.hongfu.impl.GoodsCategoryFeatureValueService;
import com.shop.cloud.service.hongfu.impl.GoodsCategoryService;
import com.shop.cloud.service.hongfu.impl.GoodsDistributionSetService;
import com.shop.cloud.service.hongfu.impl.GoodsFeatureImageService;
import com.shop.cloud.service.hongfu.impl.GoodsFeatureService;
import com.shop.cloud.service.hongfu.impl.GoodsImageService;
import com.shop.cloud.service.hongfu.impl.GoodsInventoryService;
import com.shop.cloud.service.hongfu.impl.GoodsService;
import com.shop.cloud.service.hongfu.impl.LogService;
import com.shop.cloud.service.hongfu.impl.ShopService;
import com.shop.cloud.util.ErrorCode;
import com.shop.cloud.util.Page;
import com.shop.cloud.util.Response;
import com.shop.cloud.util.ResponseUtil;

@RestController
@RequestMapping(value = "goods")
public class GoodsController extends BaseController {
	
		@Autowired
		private GoodsService goodsService;
		
		@Autowired
		private GoodsBrandService goodsBrandService;
		
		@Autowired
		private GoodsCategoryService goodsCategoryService;
		
		@Autowired
		private GoodsCategoryFeatureService goodsCategoryFeatureService;
		
		@Autowired
		private GoodsCategoryFeatureValueService goodsCategoryFeatureValueService;
		
		@Autowired
		private GoodsImageService goodsImageService;
		
		@Autowired
		private GoodsFeatureService goodsFeatureService;
		
		@Autowired
		private GoodsInventoryService goodsInventoryService;
		
		@Autowired
		private GoodsFeatureImageService goodsFeatureImageService;
		
		@Autowired
		private GoodsDistributionSetService goodsDistributionSetService;

		@Autowired
		private GoodsProductSkuService goodsProductSkuService;
		
		@Autowired
		private GoodsProductService goodsProductService;
		
		@Autowired
		private DistributionInstallService distributionInstallService;
		
		@Autowired
		private GoodsExamineDao goodsExamineDao;
		
		@Autowired
		private GoodsDao goodsDao;
		
		@Autowired
		private ShopService shopService;
		
		@Autowired
		private LogService logService;
		
		@Autowired
		private GoodsCategoryDao goodsCategoryDao;
		
		//@MagicPermission
		@ApiOperation(value = "获取商品品牌列表", notes = "获取商品品牌列表")
		@RequestMapping(value = "brandList", method = RequestMethod.POST)
		@ResponseBody
		public Response brandList(HttpServletRequest request, HttpServletResponse response,@RequestBody GetGoodsBrandListRequest getGoodsBrandListRequest) {
			List<GetGoodsBrandListResponse> datas = new ArrayList<GetGoodsBrandListResponse>();
			GetGoodsBrandListResponse data = null;
			logger.debug("获取商品品牌列表");
//			Map<String, Object> params = new HashMap<String, Object>();

			GoodsBrand goodsBrand = new GoodsBrand();
			List<GoodsBrand> listBrands = new ArrayList<GoodsBrand>();
			
			goodsBrand.setEndTime(getGoodsBrandListRequest.getEndTime());
			if ((getGoodsBrandListRequest.getKeyword() != null && !getGoodsBrandListRequest.getKeyword().trim().equals("")) && getGoodsBrandListRequest.getKeyword().length() > 0) {
				goodsBrand.setName(getGoodsBrandListRequest.getKeyword());
			}
			goodsBrand.setPageIndex(getGoodsBrandListRequest.getPageIndex_());
			goodsBrand.setPageSize(getGoodsBrandListRequest.getPageSize_());
			goodsBrand.setStartTime(getGoodsBrandListRequest.getStartTime());
			
			listBrands = goodsBrandService.find(goodsBrand);
			
			for (GoodsBrand gb : listBrands) {
				data = new GetGoodsBrandListResponse();
				data.setId(gb.getId());
				data.setName(gb.getName());
				data.setIntroduce(gb.getIntroduce());
				data.setCreatTime(gb.getCreateTime()+"");
				data.setLogo(gb.getLogo());
				datas.add(data);
			}
			
			Page<GetGoodsBrandListResponse> page = new Page<GetGoodsBrandListResponse>(goodsBrand.getPageIndex_(), goodsBrand.getPageSize_());
			page.setData(datas);
			
			long count=goodsBrandService.countByEntity(goodsBrand);
			page.setTotalCount(count);
			return ResponseUtil.ok(page);
		}
		
		//@MagicPermission
		@ApiOperation(value = "新增商品品牌", notes = "新增商品品牌")
		@RequestMapping(value = "addGoodsBrand", method = RequestMethod.POST)
		@ResponseBody
		public Response addGoodsBrand(HttpServletRequest request, HttpServletResponse response,@RequestBody AddGoodsBrandRequest addGoodsBrandRequest) {
			logger.debug("新增商品品牌");
			AddGoodsBrandResponse data = new AddGoodsBrandResponse();
			GoodsBrand goodsBrand = new GoodsBrand();
			goodsBrand.setLogo(addGoodsBrandRequest.getLogo());
			goodsBrand.setName(addGoodsBrandRequest.getName());
			goodsBrand.setIntroduce(addGoodsBrandRequest.getIntroduce());
			goodsBrand.setCreateTime(new Timestamp(System.currentTimeMillis()));
			
			if(!goodsBrandService.insert(goodsBrand)){
				return ResponseUtil.error(ErrorCode.INSERT_DATA_ERROR, "新增商品品牌失败!");
			}
			
			return ResponseUtil.ok(data);

		}
		
		//@MagicPermission
		@ApiOperation(value = "编辑商品品牌", notes = "编辑商品品牌")
		@RequestMapping(value = "editGoodsBrand", method = RequestMethod.POST)
		@ResponseBody
		public Response editGoodsBrand(HttpServletRequest request, HttpServletResponse response,@RequestBody EditGoodsBrandRequest editGoodsBrandRequest) {
			EditGoodsBrandResponse data = new EditGoodsBrandResponse();
			logger.debug("编辑商品品牌");
			GoodsBrand goodsBrand = new GoodsBrand();
			goodsBrand.setId(editGoodsBrandRequest.getId());
			goodsBrand.setLogo(editGoodsBrandRequest.getLogo());
			goodsBrand.setName(editGoodsBrandRequest.getName());
			goodsBrand.setIntroduce(editGoodsBrandRequest.getIntroduce());
			
			int flag = goodsBrandService.update(goodsBrand);
			if (flag <=0 ) {
				return ResponseUtil.error(ErrorCode.UPDATE_DATA_ERROR, "编辑商品品牌失败!");
			}
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "删除商品品牌", notes = "删除商品品牌")
		@RequestMapping(value = "deleteGoodsBrand", method = RequestMethod.POST)
		@ResponseBody
		public Response deleteGoodsBrand(HttpServletRequest request, HttpServletResponse response,@RequestBody DeleteGoodsBrandRequest deleteGoodsBrandRequest) {
			DeleteGoodsBrandResponse data = new DeleteGoodsBrandResponse();
			GoodsBrand goodsBrand = new GoodsBrand();
			logger.debug("删除商品品牌");
			goodsBrand.setId(deleteGoodsBrandRequest.getId());
			int flag = goodsBrandService.remove(goodsBrand);
			if (flag <=0 ) {
				return ResponseUtil.error(ErrorCode.REMOVE_DATE_ERROR, "删除商品品牌失败!");
			}
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "获取商品分类列表", notes = "获取商品分类列表")
		@RequestMapping(value = "categoryList", method = RequestMethod.POST)
		@ResponseBody
		public Response categoryList(HttpServletRequest request, HttpServletResponse response,@RequestBody GoodsCategory  goodsCategory) {
			/*List<GetGoodsCategoryListResponse> datas = new ArrayList<GetGoodsCategoryListResponse>();
			GetGoodsCategoryListResponse data = null;*/
			logger.debug("获取商品分类列表");
//			goodsCategory2.setId(getGoodsCategoryListRequest.getParentId());
		/*	if (getGoodsCategoryListRequest.getType() > 0) {
				goodsCategory.setType(getGoodsCategoryListRequest.getType());
			}
			*/
		/*		goodsCategory2.setName(getGoodsCategoryListRequest.getName());
			
			goodsCategory2.setPageIndex(getGoodsCategoryListRequest.getPageIndex_());
			goodsCategory2.setPageSize(getGoodsCategoryListRequest.getPageSize_());
			goodsCategory2.setOrderBy("GOODS_CATEGORY.parent_id DESC");
			List<GoodsCategory> listGoodsCategory = goodsCategoryService.find(goodsCategory2);
			for (GoodsCategory gc : listGoodsCategory) {
				data = new GetGoodsCategoryListResponse();
				if (gc.getParentId() != 0) {
					GoodsCategory	goodsCategory = new GoodsCategory();
					goodsCategory.setId(gc.getParentId());
					GoodsCategory goodsCategory1 = goodsCategoryService.findOne(goodsCategory);
					
					data.setId(gc.getId());
					data.setFirstName(goodsCategory1.getName());
					data.setSecondName(gc.getName());
					data.setTypeName(gc.getType()+"");
					data.setCreate_time(gc.getCreate_time());
					data.setLast_edit_time(gc.getUpdate_time());
					data.setpId(gc.getParentId());
					datas.add(data);
				}else {
					if (gc.getParentId() == 0) {
						//此一级分类 是否含有二级分类 没有二级分类的 加入返回data
						GoodsCategory	goodsCategory3 = new GoodsCategory();
						goodsCategory3.setParentId(gc.getId());
						GoodsCategory goodsCategory1 = goodsCategoryService.findOne(goodsCategory3);
						if (goodsCategory1 == null) {//没有二级
							data.setId(gc.getId());
							data.setpId(gc.getId());
							data.setFirstName(gc.getName());
							data.setTypeName(gc.getType()+"");
							data.setCreate_time(gc.getCreate_time());
							data.setLast_edit_time(gc.getUpdate_time());
							datas.add(data);
						}
					}
				}
			}
			

			Page<GetGoodsCategoryListResponse> page = new Page<GetGoodsCategoryListResponse>(getGoodsCategoryListRequest.getPageIndex_(), getGoodsCategoryListRequest.getPageSize_());
			page.setData(datas);
			
			long count=goodsCategoryService.countByEntity(goodsCategory2);
			page.setTotalCount(count);*/
			
			Page<GoodsCategory> page=goodsCategoryService.catePage(goodsCategory);
			return ResponseUtil.ok(page);
		}
		
		//@MagicPermission
		@ApiOperation(value = "获取商品分类列表中选择分类使用", notes = "获取商品分类列表中选择分类使用")
		@RequestMapping(value = "goodsCategoryList", method = RequestMethod.POST)
		@ResponseBody
		public Response goodsCategoryList(HttpServletRequest request, HttpServletResponse response,@RequestBody GetGoodsCategoryGradeListRequest getGoodsCategoryGradeListRequest) {
			logger.debug("获取商品分类列表中选择分类使用");
			List<GetGoodsCategoryGradeListResponse> datas = new ArrayList<GetGoodsCategoryGradeListResponse>();
			GetGoodsCategoryGradeListResponse data = null;
			
			GoodsCategory  goodsCategory = new GoodsCategory();
			goodsCategory.setParentId(getGoodsCategoryGradeListRequest.getId().intValue());
			
			List<GoodsCategory> listGoodsCategory = goodsCategoryService.find2(goodsCategory);
			for (GoodsCategory gc : listGoodsCategory) {
				data = new GetGoodsCategoryGradeListResponse();
				data.setId(gc.getId());
				data.setName(gc.getName());
				datas.add(data);
			}
			
			return ResponseUtil.ok(datas);
		}
		
		//@MagicPermission
		@ApiOperation(value = "获取所有商品分类", notes = "获取所有商品分类")
		@RequestMapping(value = "getAllGoodsCategory", method = RequestMethod.POST)
		@ResponseBody
		public Response getAllGoodsCategory(HttpServletRequest request, HttpServletResponse response,@RequestBody GetAllGoodsCategoryRequest getAllGoodsCategoryRequest) {
			logger.debug(">>>>>>获取所有商品分类<<<<<<<<");
			GetAllGoodsCategoryResponse data = new GetAllGoodsCategoryResponse();
			GoodsCategory goodsCategory = new GoodsCategory();
			List<AddGoodsCategoryRequestData> fistList = new ArrayList<AddGoodsCategoryRequestData>();
			List<AddGoodsCategoryRequestData> secondList = null;
			AddGoodsCategoryRequestData addGoodsCategoryRequestDataFirst = null;
			AddGoodsCategoryRequestData addGoodsCategoryRequestDataSecond = null;
			
			goodsCategory.setType(getAllGoodsCategoryRequest.getType());
			goodsCategory.setParentId(0);
			List<GoodsCategory> listGoodsCategory = goodsCategoryService.find(goodsCategory);//查寻type类型的数据 查询一级的数据  parentId = 0;
			
			fistList = new ArrayList<AddGoodsCategoryRequestData>();
		if (listGoodsCategory != null && listGoodsCategory.size() > 0) {// 轮询type类型的  一级数据
			for (GoodsCategory gc : listGoodsCategory) {
				data = new GetAllGoodsCategoryResponse();
				secondList = new ArrayList<AddGoodsCategoryRequestData>();

				addGoodsCategoryRequestDataFirst = new AddGoodsCategoryRequestData();
				addGoodsCategoryRequestDataFirst.setId(gc.getId());
				addGoodsCategoryRequestDataFirst.setName(gc.getName());

				// 查询 二级数据
				goodsCategory = new GoodsCategory();
				goodsCategory.setParentId(gc.getId().intValue());
				goodsCategory.setType(getAllGoodsCategoryRequest.getType());
				List<GoodsCategory> listSecond = goodsCategoryService.find(goodsCategory);
				for (GoodsCategory goodsCategory3 : listSecond) {
					addGoodsCategoryRequestDataSecond = new AddGoodsCategoryRequestData();
					addGoodsCategoryRequestDataSecond.setId(goodsCategory3.getId());
					addGoodsCategoryRequestDataSecond.setName(goodsCategory3.getName());
					secondList.add(addGoodsCategoryRequestDataSecond);
				}

				addGoodsCategoryRequestDataFirst.setSecond(secondList);// 一级list 添加 二级list
				fistList.add(addGoodsCategoryRequestDataFirst);
			}
		}
			
			data.setFirst(fistList);
			return ResponseUtil.ok(data);
		}
		
		
		//@MagicPermission
		@ApiOperation(value = "获取所有商品分类", notes = "获取所有商品分类")
		@RequestMapping(value = "getAllGoodsCategory2", method = RequestMethod.POST)
		@ResponseBody
		public Response getAllGoodsCategory2(HttpServletRequest request, HttpServletResponse response,@RequestBody GetAllGoodsCategoryRequest getAllGoodsCategoryRequest) {
			logger.debug(">>>>>>获取所有商品分类<<<<<<<<");
			GetAllGoodsCategoryResponse data = new GetAllGoodsCategoryResponse();
			GoodsCategory goodsCategory = new GoodsCategory();
			List<AddGoodsCategoryRequestData> fistList = new ArrayList<AddGoodsCategoryRequestData>();
			List<AddGoodsCategoryRequestData> secondList = null;
			AddGoodsCategoryRequestData addGoodsCategoryRequestDataFirst = null;
			AddGoodsCategoryRequestData addGoodsCategoryRequestDataSecond = null;
			
			goodsCategory.setType(getAllGoodsCategoryRequest.getType());
			goodsCategory.setParentId(0);
			List<GoodsCategory> listGoodsCategory = goodsCategoryService.find2(goodsCategory);//查寻type类型的数据 查询一级的数据  parentId = 0;
			
			fistList = new ArrayList<AddGoodsCategoryRequestData>();
		if (listGoodsCategory != null && listGoodsCategory.size() > 0) {// 轮询type类型的  一级数据
			for (GoodsCategory gc : listGoodsCategory) {
				data = new GetAllGoodsCategoryResponse();
				secondList = new ArrayList<AddGoodsCategoryRequestData>();

				addGoodsCategoryRequestDataFirst = new AddGoodsCategoryRequestData();
				addGoodsCategoryRequestDataFirst.setId(gc.getId());
				addGoodsCategoryRequestDataFirst.setName(gc.getName());

				// 查询 二级数据
				goodsCategory = new GoodsCategory();
				goodsCategory.setParentId(gc.getId().intValue());
				goodsCategory.setType(getAllGoodsCategoryRequest.getType());
				List<GoodsCategory> listSecond = goodsCategoryService.find2(goodsCategory);
				for (GoodsCategory goodsCategory3 : listSecond) {
					addGoodsCategoryRequestDataSecond = new AddGoodsCategoryRequestData();
					addGoodsCategoryRequestDataSecond.setId(goodsCategory3.getId());
					addGoodsCategoryRequestDataSecond.setName(goodsCategory3.getName());
					secondList.add(addGoodsCategoryRequestDataSecond);
				}

				addGoodsCategoryRequestDataFirst.setSecond(secondList);// 一级list 添加 二级list
				fistList.add(addGoodsCategoryRequestDataFirst);
			}
		}
			
			data.setFirst(fistList);
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "新增商品分类", notes = "新增商品分类")
		@RequestMapping(value = "addGoodsCategory", method = RequestMethod.POST)
		@ResponseBody
		public Response addGoodsCategory(HttpServletRequest request, HttpServletResponse response,@RequestBody AddGoodsCategoryRequest addGoodsCategoryRequest) {
			AddGoodsCategoryResponse data = new AddGoodsCategoryResponse();
			logger.debug(">>>>>>新增商品分类<<<<<<<<");
			GoodsCategory goodsCategoryFirst = null;
			GoodsCategory goodsCategorySecond = null;
			
			List<AddGoodsCategoryRequestData> first = addGoodsCategoryRequest.getFirst();//一级分类    id  name  second
			if (first != null && first.size() > 0) {
				for (AddGoodsCategoryRequestData addGoodsCategoryRequestData : first) {
					goodsCategoryFirst = new GoodsCategory();
					String name = addGoodsCategoryRequestData.getName();
					long firstId = addGoodsCategoryRequestData.getId();
					if (firstId == 0) {//firstId =0 新增
						goodsCategoryFirst.setType(addGoodsCategoryRequest.getType());
						goodsCategoryFirst.setName(name);
						goodsCategoryFirst.setParentId(0);
						goodsCategoryFirst.setCreateTime(new Timestamp(System.currentTimeMillis()));
						goodsCategoryFirst.setCreate_time(new Timestamp(System.currentTimeMillis()));
						goodsCategoryFirst.setEndTime(new Timestamp(System.currentTimeMillis()));	
						goodsCategoryFirst.setUpdateTime(new Timestamp(System.currentTimeMillis()));
						goodsCategoryFirst.setUpdate_time(new Timestamp(System.currentTimeMillis()));
						
						goodsCategoryService.insert(goodsCategoryFirst);
						
						List<AddGoodsCategoryRequestData> seconds = addGoodsCategoryRequestData.getSecond();//二级分类
						if (seconds != null && seconds.size() > 0) {
							for (AddGoodsCategoryRequestData addSeconds : seconds) {
								long secondId = addSeconds.getId();
								if (secondId == 0) {//secondId = 0 新增 second列
									goodsCategorySecond = new GoodsCategory();
									goodsCategorySecond.setName(addSeconds.getName());
									goodsCategorySecond.setParentId(goodsCategoryFirst.getId().intValue());
									goodsCategorySecond.setType(addGoodsCategoryRequest.getType());
									goodsCategorySecond.setCreateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setCreate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setEndTime(new Timestamp(System.currentTimeMillis()));	
									goodsCategorySecond.setUpdateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setUpdate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategoryService.insert(goodsCategorySecond);
								}else {//secondId != 0 修改此列 parendId与firstId对应
									goodsCategorySecond = new GoodsCategory();
									goodsCategorySecond.setId(secondId);
									goodsCategorySecond.setName(addSeconds.getName());
									goodsCategorySecond.setParentId(goodsCategoryFirst.getId().intValue());
									goodsCategorySecond.setType(addGoodsCategoryRequest.getType());
									goodsCategorySecond.setCreateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setCreate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setEndTime(new Timestamp(System.currentTimeMillis()));	
									goodsCategorySecond.setUpdateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setUpdate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategoryService.update(goodsCategorySecond);
								}
							}
						}
					}else {//firstId != 0  替换此Id中的内容
						goodsCategoryFirst.setId(firstId);
						goodsCategoryFirst.setType(addGoodsCategoryRequest.getType());
						goodsCategoryFirst.setName(name);
						goodsCategoryFirst.setParentId(0);
						goodsCategoryFirst.setCreateTime(new Timestamp(System.currentTimeMillis()));
						goodsCategoryFirst.setCreate_time(new Timestamp(System.currentTimeMillis()));
						goodsCategoryFirst.setEndTime(new Timestamp(System.currentTimeMillis()));	
						goodsCategoryFirst.setUpdateTime(new Timestamp(System.currentTimeMillis()));
						goodsCategoryFirst.setUpdate_time(new Timestamp(System.currentTimeMillis()));
						goodsCategoryService.update(goodsCategoryFirst);
						
						List<AddGoodsCategoryRequestData> seconds = addGoodsCategoryRequestData.getSecond();//二级分类
						if (seconds != null && seconds.size() > 0) {
							for (AddGoodsCategoryRequestData addSeconds : seconds) {
								long secondId = addSeconds.getId();
								if (secondId == 0) {//secondId = 0 新增 second列
									goodsCategorySecond = new GoodsCategory();
									goodsCategorySecond.setName(addSeconds.getName());
									goodsCategorySecond.setParentId(goodsCategoryFirst.getId().intValue());
									goodsCategorySecond.setType(addGoodsCategoryRequest.getType());
									goodsCategorySecond.setCreateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setCreate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setEndTime(new Timestamp(System.currentTimeMillis()));	
									goodsCategorySecond.setUpdateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setUpdate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategoryService.insert(goodsCategorySecond);
								}else {//secondId != 0 修改此列 parendId与firstId对应
									goodsCategorySecond = new GoodsCategory();
									goodsCategorySecond.setId(secondId);
									goodsCategorySecond.setName(addSeconds.getName());
									goodsCategorySecond.setParentId(goodsCategoryFirst.getId().intValue());
									goodsCategorySecond.setType(addGoodsCategoryRequest.getType());
									goodsCategorySecond.setCreateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setCreate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setEndTime(new Timestamp(System.currentTimeMillis()));	
									goodsCategorySecond.setUpdateTime(new Timestamp(System.currentTimeMillis()));
									goodsCategorySecond.setUpdate_time(new Timestamp(System.currentTimeMillis()));
									goodsCategoryService.update(goodsCategorySecond);
								}
							}
						}
					}
					
				}
			}
			
			return ResponseUtil.ok(data);
		}
		
		
		//@MagicPermission
		@ApiOperation(value = "新增商品分类", notes = "新增商品分类")
		@RequestMapping(value = "addGoodsCategory2", method = RequestMethod.POST)
		@ResponseBody
		public Response addGoodsCategory2(HttpServletRequest request, HttpServletResponse response,@RequestBody GoodsCategory goodsCategory) {
			AddGoodsCategoryResponse data = new AddGoodsCategoryResponse();
			logger.debug(">>>>>>新增商品分类<<<<<<<<");
			goodsCategory.setCreateTime(new Timestamp(System.currentTimeMillis()));
			goodsCategory.setUpdateTime(new Timestamp(System.currentTimeMillis()));
			return ResponseUtil.ok(goodsCategoryService.insert(goodsCategory));
		}
		
		
		//@MagicPermission
		@ApiOperation(value = "编辑商品分类", notes = "新增商品分类")
		@RequestMapping(value = "updateGoodsCategory", method = RequestMethod.POST)
		@ResponseBody
		public Response updateGoodsCategory(HttpServletRequest request, HttpServletResponse response,@RequestBody GoodsCategory goodsCategory) {
			AddGoodsCategoryResponse data = new AddGoodsCategoryResponse();
			logger.debug(">>>>>>新增商品分类<<<<<<<<");
			goodsCategory.setCreateTime(new Timestamp(System.currentTimeMillis()));
			goodsCategory.setUpdateTime(new Timestamp(System.currentTimeMillis()));
			return ResponseUtil.ok(goodsCategoryService.update(goodsCategory));
		}
		
		//@MagicPermission
		@ApiOperation(value = "编辑商品分类", notes = "编辑商品分类")
		@RequestMapping(value = "editGoodsCategory", method = RequestMethod.POST)
		@ResponseBody
		public Response editGoodsCategory(HttpServletRequest request, HttpServletResponse response,@RequestBody EditGoodsCategoryRequest editGoodsCategoryRequest) {
			logger.debug("编辑商品分类");
			EditGoodsCategoryResponse data = new EditGoodsCategoryResponse();
			GoodsCategory goodsCategorySecond = null;
			
			Long firstId = editGoodsCategoryRequest.getId();
			List<EditGoodsCategorySecondRequest> seconds = editGoodsCategoryRequest.getSecond();//二级分类
			
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("parentId", firstId);
			List<GoodsCategory> isHaveSeconds = goodsCategoryService.find(params);
			int secondSize = isHaveSeconds.size();
			
			if (seconds != null && seconds.size() > 0) {
				for (int i = 0; i<seconds.size(); i++) {
					goodsCategorySecond = new GoodsCategory();
					goodsCategorySecond.setName(seconds.get(i).getName());
					goodsCategorySecond.setUpdateTime(new Timestamp(System.currentTimeMillis()));
					goodsCategorySecond.setUpdate_time(new Timestamp(System.currentTimeMillis()));
					
					if (i < secondSize) {//有二级分类 并且第一条 已经存在的 要update , 不存在的要 insert
						goodsCategorySecond.setId(isHaveSeconds.get(i).getId());
						goodsCategoryService.update(goodsCategorySecond);
					}else {
						goodsCategorySecond.setParentId(firstId.intValue());
						goodsCategorySecond.setType(editGoodsCategoryRequest.getType());
						goodsCategorySecond.setCreateTime(new Timestamp(System.currentTimeMillis()));
						goodsCategorySecond.setCreate_time(new Timestamp(System.currentTimeMillis()));
						goodsCategorySecond.setEndTime(new Timestamp(System.currentTimeMillis()));	
						goodsCategoryService.insert(goodsCategorySecond);
					}
				}
			}
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "删除商品分类", notes = "删除商品分类")
		@RequestMapping(value = "deleteGoodsCategory", method = RequestMethod.POST)
		@ResponseBody
		public Response deleteGoodsCategory(HttpServletRequest request, HttpServletResponse response,@RequestBody DeleteGoodsCategoryRequest deleteGoodsCategoryRequest) {
			DeleteGoodsCategoryResponse data = new DeleteGoodsCategoryResponse();
			logger.debug("删除商品分类");
			
			int[] ids = deleteGoodsCategoryRequest.getIds();
			for (int i : ids) {
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("id", i);
				goodsCategoryService.remove(params);
			}
			return ResponseUtil.ok(data);

		}
		
		//@MagicPermission
		@ApiOperation(value = "获取商品分类规格列表", notes = "获取商品分类规格列表")
		@RequestMapping(value = "categoryFeatureList", method = RequestMethod.POST)
		@ResponseBody
		public Response categoryFeatureList(HttpServletRequest request, HttpServletResponse response,@RequestBody GetGoodsCategoryFeatureListRequest getGoodsCategoryFeatureListRequest) {
			List<GetGoodsCategoryFeatureListResponse> datas = new ArrayList<GetGoodsCategoryFeatureListResponse>();
			GetGoodsCategoryFeatureListResponse data = null;
			logger.debug("获取商品分类规格列表");
			GoodsCategoryFeature goodsCategoryFeature = new GoodsCategoryFeature();
			if (getGoodsCategoryFeatureListRequest.getCategoryId() != 0) {
				goodsCategoryFeature.setCategoryId(getGoodsCategoryFeatureListRequest.getCategoryId());
			}
			
			GoodsProductSku goodsProductSku=new GoodsProductSku();
			goodsProductSku.setCategoryId(getGoodsCategoryFeatureListRequest.getCategoryId());
			List<GoodsProductSku> listGoodsCF = goodsProductSkuService.find(goodsProductSku);

			return ResponseUtil.ok(listGoodsCF);
		}
		
		//@MagicPermission
		@ApiOperation(value = "新增商品分类规格", notes = "新增商品分类规格")
		@RequestMapping(value = "addGoodsCategoryFeature", method = RequestMethod.POST)
		@ResponseBody
		public Response addGoodsCategoryFeature(HttpServletRequest request, HttpServletResponse response,@RequestBody AddGoodsCategoryFeatureRequest addGoodsCategoryFeatureRequest) {
			AddGoodsCategoryFeatureResponse data = new AddGoodsCategoryFeatureResponse();
			logger.debug("新增商品分类规格");
			GoodsProductSku sku=new GoodsProductSku();
			sku.setCategoryId(addGoodsCategoryFeatureRequest.getCategoryId());
			sku.setSkuType(addGoodsCategoryFeatureRequest.getSkuType());
		    sku.setSkuValue(addGoodsCategoryFeatureRequest.getSkuValue());
		 
			if (!goodsProductSkuService.insert(sku)) {
				return ResponseUtil.error(ErrorCode.INSERT_DATA_ERROR, "新增商品分类规格失败!");
			}
			return ResponseUtil.ok(data);

		}
		
		//@MagicPermission
		@ApiOperation(value = "新增商品分类规格值", notes = "新增商品分类规格值")
		@RequestMapping(value = "addCategoryFeatureValue", method = RequestMethod.POST)
		@ResponseBody
		public Response addCategoryFeatureValue(HttpServletRequest request, HttpServletResponse response,@RequestBody AddGoodsCategoryFeatureRequest addGoodsCategoryFeatureRequest) {
			AddGoodsCategoryFeatureResponse data = new AddGoodsCategoryFeatureResponse();
			logger.debug("新增商品分类规格");
			GoodsProductSku sku=new GoodsProductSku();
			sku.setCategoryId(addGoodsCategoryFeatureRequest.getCategoryId());
			sku.setSkuType(addGoodsCategoryFeatureRequest.getSkuType());
		    sku.setSkuValue(addGoodsCategoryFeatureRequest.getSkuValue());
		 
			if (!goodsProductSkuService.insert(sku)) {
				return ResponseUtil.error(ErrorCode.INSERT_DATA_ERROR, "新增商品分类规格失败!");
			}
			return ResponseUtil.ok(data);
			
		}
		
		//@MagicPermission
		@ApiOperation(value = "删除商品分类规格", notes = "删除商品分类规格")
		@RequestMapping(value = "deleteGoodsCategoryFeature", method = RequestMethod.POST)
		@ResponseBody
		public Response deleteGoodsCategoryFeature(HttpServletRequest request, HttpServletResponse response,@RequestBody DeleteGoodsCategoryFeatureRequest deleteGoodsCategoryFeatureRequest) {
			DeleteGoodsCategoryFeatureResponse data = new DeleteGoodsCategoryFeatureResponse();
			logger.debug("删除商品分类规格");
			GoodsCategoryFeature goodsCategoryFeature = new GoodsCategoryFeature();
			goodsCategoryFeature.setId(deleteGoodsCategoryFeatureRequest.getId());
			
			int flag = goodsCategoryFeatureService.remove(goodsCategoryFeature);
			if (flag <=0 ) {
				return ResponseUtil.error(ErrorCode.REMOVE_DATE_ERROR, "删除商品分类规格失败！");
			}
			
			return ResponseUtil.ok(data);

		}
		
		//@MagicPermission
		@ApiOperation(value = "获取商品分类规格值列表", notes = "获取商品分类规格值列表")
		@RequestMapping(value = "categoryFeatureValueList", method = RequestMethod.POST)
		@ResponseBody
		public Response categoryFeatureValueList(HttpServletRequest request, HttpServletResponse response,@RequestBody GoodsProductSku goodsProductSku) {
			
			System.out.println(goodsProductSku.getType()+"========================================");
			Page<GoodsProductSku> datas=goodsProductSkuService.page(goodsProductSku);
			
			return ResponseUtil.ok(datas);

		}
		
		//@MagicPermission
		@ApiOperation(value = "新增商品分类规格值", notes = "新增商品分类规格值")
		@RequestMapping(value = "addGoodsCategoryFeatureValue", method = RequestMethod.POST)
		@ResponseBody
		public Response addGoodsCategoryFeatureValue(HttpServletRequest request, HttpServletResponse response,@RequestBody AddGoodsCategoryFeatureValueRequest addGoodsCategoryFeatureValueRequest) {
			logger.debug("新增商品分类规格值");
			AddGoodsCategoryFeatureValueResponse data = new AddGoodsCategoryFeatureValueResponse();
			GoodsCategoryFeatureValue goodsCategoryFeatureValue = new GoodsCategoryFeatureValue();
			goodsCategoryFeatureValue.setFeatureId(addGoodsCategoryFeatureValueRequest.getFeatureId());
			goodsCategoryFeatureValue.setName(addGoodsCategoryFeatureValueRequest.getName());
			
			if(goodsCategoryFeatureValueService.insert(goodsCategoryFeatureValue)){
				return ResponseUtil.error(ErrorCode.INSERT_DATA_ERROR, "新增商品分类规格值失败！");
			}
			return ResponseUtil.ok(data);

		}
		
		//@MagicPermission
		@ApiOperation(value = "删除商品分类规格值", notes = "删除商品分类规格值")
		@RequestMapping(value = "deleteCategoryFeatureValue", method = RequestMethod.POST)
		@ResponseBody
		public Response deleteCategoryFeatureValue(HttpServletRequest request, HttpServletResponse response,@RequestBody DeleteGoodsCategoryFeatureValueRequest deleteGoodsCategoryFeatureValueRequest) {
			DeleteGoodsCategoryFeatureValueResponse data = new DeleteGoodsCategoryFeatureValueResponse();
			logger.debug("删除商品分类规格值");
			
			GoodsProductSku goodsProductSku=new GoodsProductSku();
			goodsProductSku.setId(deleteGoodsCategoryFeatureValueRequest.getId());
			int flag = goodsProductSkuService.remove(goodsProductSku);
			
			if (flag <= 0 ) {
				return ResponseUtil.error(ErrorCode.REMOVE_DATE_ERROR, "删除商品分类规格值失败!");
			}
			return ResponseUtil.ok(data);

		}
		
		//@MagicPermission
		@ApiOperation(value = "获取商品列表", notes = "获取商品列表")
		@RequestMapping(value = "list", method = RequestMethod.POST)
		@ResponseBody
		public Response list(@CurrentUserId long userid,HttpServletRequest request, HttpServletResponse response,@RequestBody Goods goods) {
			logger.debug("获取商品列表");
	
			Goods goods2=goodsDao.getroleId(userid);
			
			//权限拦截
			if (goods2.getAuthority()==1) {
				List<String> longList=new ArrayList<String>();
				longList.add(goods.getRoleId()+"");
				goods.setShopIds(longList);
				goods.setsId(goods.getShopIds().get(0));
			}
			
			if (goods2.getAuthority()==2) {
				Shop shop=new Shop();
				shop.setRoleId(goods2.getRoleId());
				List<Shop> shopList=shopService.find(shop);
				List<String> strList=new ArrayList<String>();
				for (int i = 0; i < shopList.size(); i++) {
					strList.add(shopList.get(i).getId()+"");
				}
				goods.setShopIds(strList);
				goods.setsId(goods.getShopIds().get(0));
			}
			
			goods.setOrderBy("GOODS.create_time desc");
			Page<Goods> datas=goodsService.allPage(goods);
			return ResponseUtil.ok(datas);
		}
		
		//@MagicPermission
		@ApiOperation(value = "添加商品", notes = "添加商品")
		@RequestMapping(value = "add", method = RequestMethod.POST)
		@ResponseBody
		public Response addGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody AddGoodsRequest addGoodsRequest) {
			logger.debug("添加商品");
			AddGoodsResponse data = new AddGoodsResponse();
			Goods goods = new Goods();
			GoodsFeature goodsFeature = null;
			GoodsFeatureImage goodsFeatureImage = null;
			
			//查询审核开关是否开启
			Map<String, Object> params = new HashMap<String, Object>();
			List<GoodsExamine>  examineList = goodsExamineDao.find(params);
			GoodsExamine goodsExamine=examineList.get(0);
			if (goodsExamine.getExamine()==0) {
				goods.setStatus(5);//商品状态，5: 审核中 1:销售中，2审核未通过，3已下架   
			}else{
				goods.setStatus(1);
			}
			
			int type = addGoodsRequest.getType();//	 商品种类  1：鸿豆商品 2：积分商品 3：旅游商品 4：返利商品

			goods.setType(type);
			goods.setCategoryId(addGoodsRequest.getCategoryId());
			goods.setBrandId(addGoodsRequest.getBrandId());
			goods.setName(addGoodsRequest.getName());
			goods.setDetail(addGoodsRequest.getDetail());
			
			goods.setInventory(addGoodsRequest.getTotalInventory());//商品库存
			
			goods.setWarnedInventory(addGoodsRequest.getWarnedInventory());//库存预警值
			goods.setRemainInventory(addGoodsRequest.getTotalInventory());//商品剩余库存
			goods.setPrice(addGoodsRequest.getPrice());//商品价格
			goods.setMarketPrice(addGoodsRequest.getMarketPrice());//商品市场价格
		    goods.setTitle(addGoodsRequest.getTitle());
			goods.setRemark(addGoodsRequest.getRemark());
			goods.setFirstPlace(addGoodsRequest.getFirstPlace());
			goods.setSoldCount(0);
			
			goods.setCreateTime(new Timestamp(System.currentTimeMillis()));//创建时间
			
			if (type == 3) {//旅游商品
				goods.setIsTravelGoods(1);//是否旅游商品   0：否 1：是
				goods.setTravelTypeId(addGoodsRequest.getCategoryId());
				goods.setPlaceCityId(addGoodsRequest.getStartArea());//出发地 出发地城市id，只对is_travel_goods=1有效
			}
			goods.setIsSpecialPrice(addGoodsRequest.getIsSpecialPrice());//是否特价商品，0否，1是
			if (addGoodsRequest.getIsSpecialPrice() == 1) {
				goods.setSpecialPrice(addGoodsRequest.getSpecialPrice());//特价价格。当is_special_price=1时有效
				goods.setSpecialStartTime(addGoodsRequest.getSpecialStartTime());//特价开始时间当is_special_price=1时有效
				goods.setSpecialEndTime(addGoodsRequest.getSpecialEndTime());//特价结束时间当is_special_price=1时有效
			}
			goods.setReview(100.00F);//好评率
			goods.setShopId(Long.valueOf(addGoodsRequest.getRoleId()));//店铺Id
			
			
			
			goods.setCloseReason("");//下架原因
			goods.setRejectReason("");//审核未通过原因
			
			goods.setOpenDistribution(addGoodsRequest.getIsDistribution());//是否开启分销，2未开启，1已开启 
			goods.setSpec("");//商品规格
			
			boolean flag = goodsService.insert(goods);
			
			//添加商品图片集合
			GoodsImage goodsImage = null;
			for (String str : addGoodsRequest.getImg()) {
				goodsImage = new GoodsImage();
				goodsImage.setGoodsId(goods.getId());
				goodsImage.setImage(str);
				goodsImageService.insert(goodsImage);
			}
	
			//无规格
			if (addGoodsRequest.getGoodsProduct().equals("[]")) {
				GoodsProduct goodsProductWu=new GoodsProduct();
				goodsProductWu.setPrice(addGoodsRequest.getPrice());
				goodsProductWu.setGoodsId(goods.getId());
				goodsProductWu.setWarnStock(addGoodsRequest.getWarnedInventory());
				goodsProductWu.setMarketPrice(addGoodsRequest.getMarketPrice());
				goodsProductWu.setSoldVolume(0L);
				goodsProductWu.setStock((long)addGoodsRequest.getTotalInventory());
				
				goodsProductService.insert(goodsProductWu);
			}else{
			
			//添加产品规格:有规格
			  JSONArray array = new JSONArray(addGoodsRequest.getGoodsProduct());
			  
			  JSONObject object = null;
			  Long stock=0L;
			  Long warnStock=0L;
			  for (int i = 0; i < array.length(); i++) {
				     object = array.getJSONObject(i);
				     
				 	GoodsProduct goodsProduct=new GoodsProduct();
					goodsProduct.setGoodsId(goods.getId());
					goodsProduct.setPrice(Float.parseFloat(object.getString("price")));
					goodsProduct.setWarnStock(object.getInt("warnStock"));
					goodsProduct.setMarketPrice(Float.parseFloat(object.getString("marketPrice")));
					goodsProduct.setSoldVolume(object.getLong("soldVolume"));
					goodsProduct.setStock(object.getLong("stock"));
					
					stock=object.getLong("stock")+stock;
					warnStock=object.getInt("warnStock")+warnStock;
					JSONObject object2=object;
					object2.remove("price");
					object2.remove("warnStock");
					object2.remove("marketPrice");
					object2.remove("soldVolume");
					object2.remove("stock");
					goodsProduct.setSpecs(object2.toString());
			
					goodsProductService.insert(goodsProduct);
			}
			  //有规格产品修改库存
			  if (stock!=0) {
				  Goods goods2=new Goods();
				  goods2.setId(goods.getId());
				  goods2.setInventory(stock.intValue());//商品库存
				  goods2.setRemainInventory(stock.intValue());
				  goods2.setWarnedInventory(warnStock.intValue());
				  goods2.setOpenDistribution(addGoodsRequest.getIsDistribution());
				  int flagLine = goodsService.update(goods2);
			}
			}
			  
			  //添加分销
			  if (addGoodsRequest.getIsDistribution()==1) {
				  DistributionInstall distributionInstall=new DistributionInstall();
				  distributionInstall.setFromType(0);
				  distributionInstall.setFromId(goods.getId());
				  distributionInstall.setStatus(0);
				  distributionInstall.setRemark("商品分销设置");
				  Date date = new Date();  
			      Timestamp ts = new Timestamp(date.getTime());  
				  distributionInstall.setCreateTime(ts);
				  
				  List<Float> distributions = addGoodsRequest.getDistributionSet();
				  List<DescGoods> list=new ArrayList<DescGoods>();
				  
				  DescGoods descGoods=new DescGoods();
				  descGoods.setDesc_name("一级");
				  descGoods.setDesc_value(distributions.get(0).toString());
				  list.add(descGoods);
				  
				  DescGoods descGoods2=new DescGoods();
				  descGoods2.setDesc_name("二级");
				  descGoods2.setDesc_value(distributions.get(1).toString());
				  list.add(descGoods2);
				  
				  distributionInstall.setDistriSetting(new Gson().toJson(list));
				  distributionInstallService.insert(distributionInstall);
				  
				  Goods goods2=new Goods();
				  goods2.setId(goods.getId());
				  goods2.setOpenDistribution(1);
				  goodsService.update(goods2);
			}
			 
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "编辑商品", notes = "编辑商品")
		@RequestMapping(value = "update", method = RequestMethod.POST)
		@ResponseBody
		public Response editGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody EditGoodsRequest editGoodsRequest) {
			EditGoodsResponse data = new EditGoodsResponse();
			
			Goods goods = new Goods();
			GoodsFeature goodsFeature = null;
			GoodsFeatureImage goodsFeatureImage = null;
			
			int type = editGoodsRequest.getType();//	 商品种类  1：鸿豆商品 2：积分商品 3：旅游商品 4：返利商品

			goods.setId(editGoodsRequest.getId());
			goods.setType(type);
			goods.setCategoryId(editGoodsRequest.getCategoryId());
			goods.setBrandId(editGoodsRequest.getBrandId());
			goods.setName(editGoodsRequest.getName());
			goods.setDetail(editGoodsRequest.getDetail());
			
			goods.setInventory(editGoodsRequest.getTotalInventory());//商品库存
			
			goods.setWarnedInventory(editGoodsRequest.getWarnedInventory());//库存预警值
			goods.setRemainInventory(editGoodsRequest.getTotalInventory());//商品剩余库存
			goods.setPrice(editGoodsRequest.getPrice());//商品价格
			goods.setMarketPrice(editGoodsRequest.getMarketPrice());//商品市场价格
		    goods.setTitle(editGoodsRequest.getTitle());
			goods.setRemark(editGoodsRequest.getRemark());
			goods.setFirstPlace(editGoodsRequest.getFirstPlace());
			
			if (type == 3) {//旅游商品
				goods.setIsTravelGoods(1);//是否旅游商品   0：否 1：是
				goods.setTravelTypeId(editGoodsRequest.getCategoryId());
				goods.setPlaceCityId(editGoodsRequest.getStartArea());//出发地 出发地城市id，只对is_travel_goods=1有效
			}
			goods.setIsSpecialPrice(editGoodsRequest.getIsSpecialPrice());//是否特价商品，0否，1是
			if (editGoodsRequest.getIsSpecialPrice() == 1) {
				goods.setSpecialPrice(editGoodsRequest.getSpecialPrice());//特价价格。当is_special_price=1时有效
				goods.setSpecialStartTime(editGoodsRequest.getSpecialStartTime());//特价开始时间当is_special_price=1时有效
				goods.setSpecialEndTime(editGoodsRequest.getSpecialEndTime());//特价结束时间当is_special_price=1时有效
			}
			goods.setShopId(Long.valueOf(editGoodsRequest.getRoleId()));//店铺Id
			
			goods.setOpenDistribution(editGoodsRequest.getIsDistribution());//是否开启分销 ，0未开启，1已开启 
			
			int flagLine = goodsService.update(goods);
		
			
			if (flagLine>0) {
				
				
				//添加商品图片集合
				GoodsImage goodsImg=new GoodsImage();
				goodsImg.setGoodsId(editGoodsRequest.getId());
				goodsImageService.remove(goodsImg);
				GoodsImage goodsImage = null;
				for (String str : editGoodsRequest.getImg()) {
					goodsImage = new GoodsImage();
					goodsImage.setGoodsId(editGoodsRequest.getId());
					goodsImage.setImage(str);
					goodsImageService.insert(goodsImage);
				}
		
				/*if (editGoodsRequest.getSkuList().size()>0) {
					for (int i = 0; i < editGoodsRequest.getSkuList().size(); i++) {
						ProductSku sku=editGoodsRequest.getSkuList().get(i);
						
						GoodsProduct goodsP=new GoodsProduct();
						goodsP.setId(sku.getProductId());
						goodsP.setStock(sku.getProductStock());
						goodsP.setPrice(sku.getProductPrice());
						goodsProductService.update(goodsP);
					}
				}*/
				
				
				
				/*GoodsProduct goodsP=new GoodsProduct();
				goodsP.setGoodsId(editGoodsRequest.getId());
				goodsProductService.remove(goodsP);*/
				
				
				//无规格
			/*	if (editGoodsRequest.getGoodsProduct().equals("[]")) {
					GoodsProduct goodsProductWu=new GoodsProduct();
					goodsProductWu.setPrice(editGoodsRequest.getPrice());
					goodsProductWu.setGoodsId(editGoodsRequest.getId());
					goodsProductWu.setWarnStock(editGoodsRequest.getWarnedInventory());
					goodsProductWu.setMarketPrice(editGoodsRequest.getMarketPrice());
					goodsProductWu.setSoldVolume(0L);
					goodsProductWu.setStock((long)editGoodsRequest.getTotalInventory());
					
					
					goodsProductService.insert(goodsProductWu);
				}else{
				//添加产品规格:有规格
				  JSONArray array = new JSONArray(editGoodsRequest.getGoodsProduct());
				  
				  JSONObject object = null;
				  Long stock=0L;
				  Long warnStock=0L;
				  for (int i = 0; i < array.length(); i++) {
					     object = array.getJSONObject(i);
					     
					 	GoodsProduct goodsProduct=new GoodsProduct();
						goodsProduct.setGoodsId(editGoodsRequest.getId());
						goodsProduct.setPrice(Float.parseFloat(object.getString("price")));
						goodsProduct.setWarnStock(object.getInt("warnStock"));
						goodsProduct.setMarketPrice(Float.parseFloat(object.getString("marketPrice")));
						goodsProduct.setSoldVolume(object.getLong("soldVolume"));
						goodsProduct.setStock(object.getLong("stock"));
						
						stock=object.getLong("stock")+stock;
						warnStock=object.getInt("warnStock")+warnStock;
						JSONObject object2=object;
						object2.remove("price");
						object2.remove("warnStock");
						object2.remove("marketPrice");
						object2.remove("soldVolume");
						object2.remove("stock");
						goodsProduct.setSpecs(object2.toString());
				
						goodsProductService.insert(goodsProduct);
				}
				  //有规格产品修改库存
				  if (stock!=0) {
					  Goods goods2=new Goods();
					  goods2.setId(editGoodsRequest.getId());
					  goods2.setInventory(stock.intValue());//商品库存
					  goods2.setRemainInventory(stock.intValue());
					  goods2.setWarnedInventory(warnStock.intValue());
					 goodsService.update(goods2);
				}
				}*/
				  
				  //添加分销
				DistributionInstall distribution=new DistributionInstall();
				distribution.setFromId(editGoodsRequest.getId());
				distributionInstallService.remove(distribution);
				
				  if (editGoodsRequest.getIsDistribution()==1) {
					  DistributionInstall distributionInstall=new DistributionInstall();
					  distributionInstall.setFromType(0);
					  distributionInstall.setFromId(editGoodsRequest.getId());
					  distributionInstall.setStatus(0);
					  distributionInstall.setRemark("商品分销设置");
					  Date date = new Date();  
				      Timestamp ts = new Timestamp(date.getTime());  
					  distributionInstall.setCreateTime(ts);
					  
					  List<Float> distributions = editGoodsRequest.getDistributionSet();
					  List<DescGoods> list=new ArrayList<DescGoods>();
					  
					  DescGoods descGoods=new DescGoods();
					  descGoods.setDesc_name("一级");
					  descGoods.setDesc_value(distributions.get(0).toString());
					  list.add(descGoods);
					  
					  DescGoods descGoods2=new DescGoods();
					  descGoods2.setDesc_name("二级");
					  descGoods2.setDesc_value(distributions.get(1).toString());
					  list.add(descGoods2);
					  
					  distributionInstall.setDistriSetting(new Gson().toJson(list));
					  distributionInstallService.insert(distributionInstall);
					  
					  
					  Goods goods2=new Goods();
					  goods2.setId(editGoodsRequest.getId());
					  goods2.setOpenDistribution(1);
					  goodsService.update(goods2);
				}
				
			}
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "删除商品", notes = "删除商品")
		@RequestMapping(value = "delete", method = RequestMethod.POST)
		@ResponseBody
		public Response deleteGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody DeleteGoodsRequest deleteGoodsRequest) {
			DeleteGoodsResponse data = new DeleteGoodsResponse();
			/* 只更改status值，不要删除记录 */
			Goods goods = new Goods();
			goods.setId(deleteGoodsRequest.getId());
			goods.setStatus(4);
			goodsService.update(goods);
			
			return ResponseUtil.ok(data);

		}
		
		
		//@MagicPermission
				@ApiOperation(value = "编辑库存", notes = "编辑库存")
				@RequestMapping(value = "updateProduct", method = RequestMethod.POST)
				@ResponseBody
				public Response updateProduct(@CurrentUserId Long userId,HttpServletRequest request, HttpServletResponse response,@RequestBody ProductSku sku) {
					
					GoodsProduct goodsP=new GoodsProduct();
					goodsP.setId(sku.getProductId());
					goodsP.setStock(sku.getProductStock());
					goodsP.setPrice(sku.getProductPrice());
					goodsProductService.update(goodsP);
					
					logService.addLog(userId, 0,"编辑库存");
					return ResponseUtil.ok(goodsProductService.update(goodsP));

				}
		
		//@MagicPermission
		@ApiOperation(value = "获取商品信息", notes = "获取商品信息")
		@RequestMapping(value = "info", method = RequestMethod.POST)
		@ResponseBody
		public Response deleteGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody GetGoodsInfoRequest getGoodsInfoRequest) {
			GetGoodsInfoResponse data =  new GetGoodsInfoResponse();;
			GoodsInventory goodsInventory = null;
			List<GoodsInventory> goodsInventorys = null;
			GoodsCategoryFeature goodsCategoryFeature = null;
			GoodsFeatureImage goodsFeatureImage = null;
			
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("id", getGoodsInfoRequest.getId());
			
			GoodsProduct goodsProduct=new GoodsProduct();
			goodsProduct.setGoodsId(getGoodsInfoRequest.getId());
			 List<GoodsProduct> goodsProductList=goodsProductService.find(goodsProduct);
			Goods good = goodsService.findOne(params);
			good.setGoodsProduct(goodsProductList);
			
			DistributionInstall distributionInstall=new DistributionInstall();
			distributionInstall.setFromId(getGoodsInfoRequest.getId());
			List<DistributionInstall> distributionInstallsList=distributionInstallService.find(distributionInstall);
			
			if (distributionInstallsList.size()>0) {
				Gson gson=new Gson();
				List<DescGoods> descGoodsList =gson.fromJson(distributionInstallsList.get(0).getDistriSetting(), new TypeToken<List<DescGoods>>() {}.getType());
				good.setInstallOne(descGoodsList.get(0).getDesc_value());
				good.setInstallTwo(descGoodsList.get(1).getDesc_value());
			}
			
			GoodsImage goodsImage=new GoodsImage();
			goodsImage.setGoodsId(getGoodsInfoRequest.getId());
			List<GoodsImage> imageList=goodsImageService.find(goodsImage);
			good.setGoodsImages(imageList);
			
		/*	//拼接 categoryArr 
			//categoryArr 添加商品时 只选了一级分类 就[1级分类id]     选了二级分类就 [1级分类id,2级分类id]
			GoodsCategory goodsCategory = new GoodsCategory();
			List<Long> categoryIds = new ArrayList<Long>();
			goodsCategory.setId(good.getCategoryId());
			goodsCategory = goodsCategoryService.findOne(goodsCategory);
			if (goodsCategory.getParentId() == 0) {//一级
				categoryIds.add(goodsCategory.getId());
			}else {
				boolean flag = true;
				int i = 0;
				GoodsCategory tem = new GoodsCategory();
				categoryIds.add(goodsCategory.getId());
				while (flag) {
					if (i == 0) {
						tem.setParentId(goodsCategory.getParentId());
					}
					GoodsCategory goodsCategoryArrTem = new GoodsCategory();
					goodsCategoryArrTem.setId(tem.getParentId());
					tem = goodsCategoryService.findOne(goodsCategoryArrTem);
					if (tem != null) {
						categoryIds.add(tem.getId());
					}else {
						flag = false;
						Collections.reverse(categoryIds);
						break;
					}
					i++;
				}
			}
			data.setCategoryArr(categoryIds);
			
			goodsInventory = new GoodsInventory();
			goodsInventorys = new ArrayList<GoodsInventory>();
			data.setId(good.getId());
			data.setPriceType(good.getType());//价格类型，1为元，2为积分
			data.setPrice(good.getPrice());//商品价格，积分或金额
			data.setCategoryId(good.getCategoryId());//商品分类id
			data.setBrandId(good.getBrandId());//商品品牌id
			data.setName(good.getName());//商品名称
			data.setMarketPrice(good.getMarketPrice());//市场价
			//商品库存列表
			goodsInventory.setGoodsId(good.getId());
			GoodsInventory goodsInventoryResult = goodsInventoryService.findOne(goodsInventory);
			goodsInventorys.add(goodsInventoryResult);
			data.setGoodsInventorys(goodsInventorys);
			
			data.setTotalInventory(good.getInventory());//商品总库存
			data.setWarnedInventory(good.getWarnedInventory());//库存预警值
			data.setType(good.getType());//1鸿福商城，2积分商城，3旅游商品,4返利商城
			//是否有规格设置。0否，1是
			goodsCategoryFeature = new GoodsCategoryFeature();
			goodsCategoryFeature.setCategoryId(good.getCategoryId());
			List<GoodsCategoryFeature> listGoodsFeature = goodsCategoryFeatureService.find(goodsCategoryFeature);
			if (listGoodsFeature != null && listGoodsFeature.size() > 0) {
				data.setHaveFeature(1);
				//Map<Long, List<Long>>。选择的商品规格,关键词feature后面跟的是规格id号，当haveFeature＝1时有效。
				GoodsFeature goodsFeature = new GoodsFeature();
				goodsFeature.setGoodsId(good.getId());
				List<GoodsFeature> goodsFeatures = goodsFeatureService.find(goodsFeature);
				Map<Long, List<Long>>  featuresMap = new HashMap<Long, List<Long>>();
				for (GoodsFeature gF : goodsFeatures) {
					String value = gF.getValue();
					List<Long> listLong = new ArrayList<Long>();
					if (!value.equals("")) {
						String[] l = value.split(",");
						for (String str : l) {
							long longValue = Long.valueOf(str);
							listLong.add(longValue);
						}
					}
					featuresMap.put(gF.getCategoryFeatureId(), listLong);
				}
				data.setSelectedFeatures(featuresMap);
			}else {
				data.setHaveFeature(0);
			}
			
			//Map<String,String>。商品规格图片集合,关键词为规格id的集合，如[1,2]
			Map<String, String> mapFeatureImages = new HashMap<String, String>();
			goodsFeatureImage = new GoodsFeatureImage();
			goodsFeatureImage.setGoodsId(good.getId());
			goodsFeatureImage = goodsFeatureImageService.findOne(goodsFeatureImage);
			if (goodsFeatureImage != null) {
				mapFeatureImages.put(goodsFeatureImage.getGoodsFeatureId(), goodsFeatureImage.getImage());
				data.setFeatureImages(mapFeatureImages);
			}
			
			// data.setPics(good.get);//商品图片集合
			List<String> listPics = new ArrayList<String>();
			GoodsImage goodsImage = new GoodsImage();
			goodsImage.setGoodsId(good.getId());
			List<GoodsImage> listGoodsImages = goodsImageService.find(goodsImage);
			for (GoodsImage img : listGoodsImages) {
				listPics.add(img.getImage());
			}
			data.setPics(listPics);
			
			data.setDetail(good.getDetail());//商品描述
			data.setIsSpecialPrice(good.getIsSpecialPrice());//是否特价商品，0否，1是
			if (good.getIsSpecialPrice() == 1) {
				data.setSpecialPrice(good.getSpecialPrice());//特价价格，当isSpecialPrice=1时有效
				data.setSpecialStartTime(String.valueOf(good.getSpecialStartTime()));//特价开始时间，格式：YYYY-mm-dd hh:mm:ss，当isSpecialPrice=1时有效
				data.setSpecialEndTime(String.valueOf(good.getSpecialEndTime()));//特价结束时间，格式：YYYY-mm-dd hh:mm:ss，当isSpecialPrice=1时有效
			}
			
			data.setIsDistribution(good.getOpenDistribution());//是否开启分销提成，0否，1是
			if (good.getOpenDistribution() == 1) {
				//分销设置，当isDistribution=1时有效。列表形式，从1级开始往下，例如[20,12.5]
				GoodsDistributionSet goodsDistributionSet = new GoodsDistributionSet();
				goodsDistributionSet.setGoodsId(good.getId());
				List<GoodsDistributionSet> listGoodsDistributionSet = goodsDistributionSetService.find(goodsDistributionSet);
				
				if (listGoodsDistributionSet != null && listGoodsDistributionSet.size()>0) {
					List<Float> distributionSet = new ArrayList<Float>();
					int size = listGoodsDistributionSet.size();
					for (int i = 0; i < size; i++) {
						goodsDistributionSet = new GoodsDistributionSet();
						goodsDistributionSet.setGoodsId(good.getId());
						goodsDistributionSet.setLevel(i+1);
						GoodsDistributionSet temp = goodsDistributionSetService.findOne(goodsDistributionSet);
						
						distributionSet.add(temp.getReward());
					}
					data.setDistributionSet(distributionSet);
				}
			}*/
			return ResponseUtil.ok(good);
		}
		
		//@MagicPermission
		@ApiOperation(value = "审核商品", notes = "审核商品")
		@RequestMapping(value = "checkGoods", method = RequestMethod.POST)
		@ResponseBody
		public Response checkGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody CheckGoodsRequest checkGoodsRequest) {
			CheckGoodsResponse data = new CheckGoodsResponse();
			logger.debug("审核商品");
			//商品状态，0: 审核中 1:销售中，2审核未通过，3已下架，4已删除'
			
			List<Long> ids = checkGoodsRequest.getIds();
			if (ids != null && ids.size() > 0) {
				for (Long l : ids) {
					Goods goods = new Goods();
					goods.setId(l);
					goods.setStatus(checkGoodsRequest.getType());
					if (checkGoodsRequest.getType() == 2) {//审核类型。1通过，2不通过
						goods.setRejectReason(checkGoodsRequest.getReason());
					}
					goodsService.update(goods);
				}
			}
			return ResponseUtil.ok(data);

		}
		
		//@MagicPermission
		@ApiOperation(value = "使能或禁用商品审核开关", notes = "使能或禁用商品审核开关")
		@RequestMapping(value = "enableCheckGoods", method = RequestMethod.POST)
		@ResponseBody
		public Response enableCheckGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody EnableCheckGoodsRequest enableCheckGoodsRequest) {
			EnableCheckGoodsResponse data = new EnableCheckGoodsResponse();
			logger.debug("使能或禁用商品审核开关");
			Map<String, Object> params = new HashMap<String, Object>();
			List<GoodsExamine>  examineList = goodsExamineDao.find(params);
			GoodsExamine goodsExamine=examineList.get(0);
			
			return ResponseUtil.ok(goodsExamine.getExamine());

		}
		
		
		//@MagicPermission
		@ApiOperation(value = "使能或禁用商品审核开关", notes = "使能或禁用商品审核开关")
		@RequestMapping(value = "enableCheckGoods2", method = RequestMethod.POST)
		@ResponseBody
		public Response enableCheckGoods2(HttpServletRequest request, HttpServletResponse response,@RequestBody EnableCheckGoodsRequest enableCheckGoodsRequest) {
			EnableCheckGoodsResponse data = new EnableCheckGoodsResponse();
			logger.debug("使能或禁用商品审核开关");
			Map<String, Object> params = new HashMap<String, Object>();
			List<GoodsExamine>  examineList = goodsExamineDao.find(params);
			GoodsExamine goodsExamine=examineList.get(0);
			
			if (goodsExamine.getExamine()==0) {
				goodsExamine.setExamine(1);
			}else{
				goodsExamine.setExamine(0);
			}
			
			goodsExamineDao.update(goodsExamine);
			
			
			return ResponseUtil.ok(goodsExamine.getExamine());

		}

		//@MagicPermission
		@ApiOperation(value = "上架商品", notes = "上架商品")
		@RequestMapping(value = "openGoods", method = RequestMethod.POST)
		@ResponseBody
		public Response openGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody OpenGoodsRequest openGoodsRequest) {
			OpenGoodsResponse data = new OpenGoodsResponse();
			logger.debug("上架商品");
			
			Goods goods = new Goods();
			goods.setId(openGoodsRequest.getId());
			goods.setStatus(1);//0: 审核中 1:销售中，2审核未通过，3已下架
			int flag = goodsService.update(goods);
			if (flag <= 0) {
				return ResponseUtil.error(ErrorCode.UPDATE_DATA_ERROR, "上架商品失败");
			}
			return ResponseUtil.ok(data);
		}

		//@MagicPermission
		@ApiOperation(value = "下架商品", notes = "下架商品")
		@RequestMapping(value = "closeGoods", method = RequestMethod.POST)
		@ResponseBody
		public Response closeGoods(HttpServletRequest request, HttpServletResponse response,@RequestBody CloseGoodsRequest closeGoodsRequest) {
			logger.debug("下架商品");
			CloseGoodsResponse data = new CloseGoodsResponse();
			
			Goods goods = new Goods();
			goods.setId(closeGoodsRequest.getId());
			goods.setStatus(3);//0: 审核中 1:销售中，2审核未通过，3已下架
			goods.setCloseReason(closeGoodsRequest.getReason());
			
			int flag = goodsService.update(goods);
			
			if (flag <= 0) {
				return ResponseUtil.error(ErrorCode.UPDATE_DATA_ERROR, "下架商品失败");
			}
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "查看商品审核不通过原因", notes = "下架商品")
		@RequestMapping(value = "viewGoodsRejectedReason", method = RequestMethod.POST)
		@ResponseBody
		public Response viewGoodsRejectedReason(HttpServletRequest request, HttpServletResponse response,@RequestBody ViewGoodsRejectedReasonRequest viewGoodsRejectedReasonRequest) {
			logger.debug("查看商品审核不通过原因");
			ViewGoodsRejectedReasonResponse data = new ViewGoodsRejectedReasonResponse();
			
			Goods goods = new Goods();
			goods.setId(viewGoodsRejectedReasonRequest.getId());
			
			goods = goodsService.findOne(goods);
			data.setReason(goods.getCloseReason());
			return ResponseUtil.ok(data);
		}
		
		//@MagicPermission
		@ApiOperation(value = "添加商品中获取分类列表", notes = "获取分类列表")
		@RequestMapping(value = "getAllCategoryFeatureList", method = RequestMethod.POST)
		@ResponseBody
		public Response getAllCategoryFeatureList(HttpServletRequest request, HttpServletResponse response,@RequestBody GetAllCategoryFeatureListRequest getAllCategoryFeatureListRequest) {
			logger.debug("获取规格列表");
			GetAllCategoryFeatureListResponse data = null;
			GetAllCategoryFeatureListResponse dataGoodsValue = null;
			GoodsCategoryFeatureValue goodsCategoryFeatureValue = null;
			List<GetAllCategoryFeatureListResponse> listValueDatas = null;
			List<GetAllCategoryFeatureListResponse> datas = new ArrayList<GetAllCategoryFeatureListResponse>();
			
			GoodsCategoryFeature goodsCategoryFeature = new GoodsCategoryFeature();
			goodsCategoryFeature.setCategoryId(getAllCategoryFeatureListRequest.getCategoryId());
			List<GoodsCategoryFeature> listGoodsCategoryFeature = goodsCategoryFeatureService.find(goodsCategoryFeature);
			if (listGoodsCategoryFeature != null && listGoodsCategoryFeature.size() > 0) {
				for (GoodsCategoryFeature goodsCategoryFeature2 : listGoodsCategoryFeature) {
					listValueDatas = new ArrayList<GetAllCategoryFeatureListResponse>();
					
					data = new GetAllCategoryFeatureListResponse();
					data.setId(goodsCategoryFeature2.getId()+"");
					data.setName(goodsCategoryFeature2.getName());
					
					goodsCategoryFeatureValue = new GoodsCategoryFeatureValue();
					goodsCategoryFeatureValue.setFeatureId(goodsCategoryFeature2.getId());
					List<GoodsCategoryFeatureValue> listGoodsValue = goodsCategoryFeatureValueService.find(goodsCategoryFeatureValue);
					
					if (listGoodsValue != null && listGoodsValue.size() > 0) {
						for (GoodsCategoryFeatureValue goodsValue : listGoodsValue) {
							dataGoodsValue = new GetAllCategoryFeatureListResponse();
							dataGoodsValue.setId(goodsValue.getId()+"");
							dataGoodsValue.setName(goodsValue.getName());
							listValueDatas.add(dataGoodsValue);
						}
					}
					data.setValue(listValueDatas);
					datas.add(data);
				}
			}
			
			return ResponseUtil.ok(datas);
		}
		
		
		@ApiOperation(value = "获取分类的sku列表", notes = "获取分类的sku列表")
		@RequestMapping(value = "getSkuList", method = RequestMethod.POST)
		@ResponseBody
		public Response getSkuList(HttpServletRequest request, HttpServletResponse response,@RequestBody GoodsProductSku goodsProductSku){
			
			if (StringUtils.isBlank(goodsProductSku.getCategoryId().toString())) {
				return ResponseUtil.ok(null);
			}
			List<GoodsProductSku> goodsProductSkuList = goodsProductSkuService.find(goodsProductSku);
			
			ListToMap mm = new ListToMap();
			
			for (int i = 0; i < goodsProductSkuList.size(); i++) {
				GoodsProductSku sku=goodsProductSkuList.get(i);
				mm.createClass(sku.getSkuType(), sku.getId().toString(), sku.getSkuValue());
			}
			
			Map<String,List> map=mm.getAll();
		
			 List<Object> list=new ArrayList<Object>();
			  for (String key : map.keySet()) {
					Map<String,List> map2=new HashMap<String, List>();
				  map2.put(key, map.get(key));
				  list.add(map2);
				  }
			System.out.println(new Gson().toJson(list));
			return ResponseUtil.ok(list);
		}
		
		//@MagicPermission
		@ApiOperation(value = "获取商家列表", notes = "获取商家列表")
		@RequestMapping(value = "getShopList", method = RequestMethod.POST)
		@ResponseBody
		public Response getShopList(HttpServletRequest request, HttpServletResponse response,@RequestBody GoodsCategory  goodsCategory) {
			logger.debug("获取商品分类列表");

			List<Shop> list=shopService.find(new Shop());
			return ResponseUtil.ok(list);
		}
		
		//@MagicPermission
				@ApiOperation(value = "获取一级分类列表", notes = "获取商家列表")
				@RequestMapping(value = "getFirstCategory", method = RequestMethod.POST)
				@ResponseBody
				public Response getFirstCategory(HttpServletRequest request, HttpServletResponse response,@RequestBody GoodsCategory  goodsCategory) {
					logger.debug("获取一级分类列表");

					
					if (goodsCategory==null) {
						return ResponseUtil.ok(null);
					}
					
				    //一级
				    List<GoodsCategory> goodsCategoryList=goodsCategoryDao.queryCategory(goodsCategory);
				    
					//二级
				/*	List<GoodsCategory> goodsCategoryListRes=new ArrayList<GoodsCategory>();
					for (int i = 0; i < goodsCategoryList.size(); i++) {
						GoodsCategory goodsCategoryT=goodsCategoryList.get(i);
						
						GoodsCategory goodsCategoryTwo=new GoodsCategory();
						goodsCategoryTwo.setParentId(goodsCategoryT.getId().intValue());
						List<GoodsCategory> goodsCategoryList2=goodsCategoryDao.queryCategoryTwo(goodsCategoryTwo);
						goodsCategoryT.setGoodsCategorys(goodsCategoryList2);
						
						goodsCategoryListRes.add(goodsCategoryT);
					}*/
					return ResponseUtil.ok(goodsCategoryList);
				}
		
		private List<String> stringToList(String strs){
			String str[] = strs.split(",");
			return Arrays.asList(str);
			}
		
		
		public static void main(String[] args) {
		}
		
	
}
